
-- test function
function createImgTable()
    
    imgRunWinTable1 ={}
    
    gridX = 3
    gridY = 4
    
    red,r1 = 10,150
    green,g1 = 100,0
    blue,b1 = 50,0
    
    
    
    for k = 1, (gridY*gridX), 1 do
        myImg = image(WIDTH/gridX,HEIGHT/gridY)
        setContext(myImg)
        
        background()
        strokeWidth(0)
        
        fill(red,green,blue,255)
        rect(0,HEIGHT/(gridY*2),WIDTH/gridX,HEIGHT/gridY)
        
        --fill((red+r1)%255,green+g1,blue+b1,255)
        fill(255-red,255-green,255-blue,255)
        text(k,0,HEIGHT/(gridY*2))
        
        fill(red,200,0,255)
        rect(0,0,WIDTH/gridX,HEIGHT/(gridY*2))
        
        fill(100,255,0,255)
        text(k,0,0)
        
        setContext()
        
        if #imgRunWinTable1 < 120 then
            --table.insert(imgRunWinTable1,myImg)
        end
        
        imgRunWinTable1[k] = myImg
        myImg = nil
        imgRunWinTable2[k] = k
    end
    
    --[[
    for k,v in ipairs(imgRunWinTable1) do
        setContext(myImg)
        
        background()
        
        fill(155,100,k*10,255)
        rect(0,0,WIDTH,HEIGHT)
        fill(0,255,0,255)
        
        text(k,0,0)
        setContext()
        
        imgRunWinTable1[k] = myImg
        v = k
    end
    --]]
    
end



-- test function
function screenRect(imgTable,row,column)
    --test code gridX = 4, gridY = 3
    local gridX,gridY = column,row
    
    for i = 1,gridX,1 do
        for j = 1,gridY,1 do
            if imgTable[j+(i-1)*gridY] ~= nil then
                --sprite(imgTable[j+3*(i-1)], (j-1)*WIDTH/3 ,(4-i)*HEIGHT/4, WIDTH/3,HEIGHT/4)
                sprite(imgTable[j+(i-1)*gridY], (j-1)*WIDTH/gridY, (gridX-i)*HEIGHT/gridX, WIDTH/gridY, HEIGHT/gridX)
            end
        end
    end

    --[[
    --print(#structTutorialTable)
        --if #imgRunWinTable == 12 then
        for i = 1,#structTutorialTable,1 do
            -- remove the wrapline 
            --local titleText = " "..string.sub(structTutorialTable[i]["title"],1,-2)
            --local titleW,titleH = textSize(titleText)
            if imgRunWinTable[i] ~= nil then
                if i <= 3 then
                    sprite(imgRunWinTable[i], (i-1)*WIDTH/gridX ,HEIGHT*(gridY-1)/gridY, WIDTH/gridX,HEIGHT/gridY)
                end
                
                if i>3 and i <= 6 then
                    sprite(imgRunWinTable[i], (i-4)*WIDTH/gridX ,HEIGHT*(gridY-2)/gridY, WIDTH/gridX,HEIGHT/gridY)
                end
                
                if i>6 and i <= 9 then
                    sprite(imgRunWinTable[i], (i-7)*WIDTH/gridX ,HEIGHT*(gridY-3)/gridY, WIDTH/gridX,HEIGHT/gridY)
                end
                
                if i>9 and i <= 11 then
                    sprite(imgRunWinTable[i], (i-10)*WIDTH/gridX ,0, WIDTH/gridX,HEIGHT/gridY)
                end
            end
        end
        --end
    --]]
end

function setup()
    
    displayMode(FULLSCREEN)
    rectMode(CORNER)
    textMode(CORNER)
    spriteMode(CORNER)
    
    imgRunWinTable1 = {}
    imgRunWinTable2 = {}
    
    myImg = image(WIDTH/12,HEIGHT/10)
    createImgTable()
end

function draw()
    background()
    sprite(imgRunWinTable1[2],0,0)
    text(imgRunWinTable2[6],100,100)
    screenRect(imgRunWinTable1,gridX,gridY)
end
